package com.anolesoft.amljmes.screen.mapper;

import com.anolesoft.amljmes.screen.dto.MesOrderAssess;
import com.anolesoft.amljmes.screen.dto.MesOrderTimeoutLogs;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;


@Mapper
public interface MesOrderAssessMapper {
    // 根据机型查询考核表及日志表,显示厂代号,在制数,待归档数,1-10,11-20,21-30,30以上,考核项个数
    // 不输入年月查询两张表关联出考核项,输入年月查询一张表
    // 根据厂代号和机型统计厂代号
    @SelectProvider(type= MesOrderAssessMapper.createSQL.class, method = "querykaohe1")
    Integer selectone(MesOrderTimeoutLogs mesOrderTimeoutLogs);
    public static class createSQL {
        public static String querykaohe1(MesOrderTimeoutLogs mesOrderTimeoutLogs){
            return new SQL(){
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" count(1) kaohexiang\n" +
                            " from mes_order_assess t " +
                            " where t.versions = 0 and ASSESSMENT = '0'");
                    if(mesOrderTimeoutLogs.getJx()!=null&&!String.valueOf(mesOrderTimeoutLogs.getJx()).equals("")){
                        String jx = mesOrderTimeoutLogs.getJx().toUpperCase();
                        sql.append(" and t.jx = #{jx}");
                    }
                    if(mesOrderTimeoutLogs.getFactoryId()!=null&&!String.valueOf(mesOrderTimeoutLogs.getFactoryId()).equals("")){
                        String factoryId = mesOrderTimeoutLogs.getFactoryId();
                        sql.append(" and t.factory_id = #{factoryId}");
                    }
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }

    // 如果输入年月查询一张表数据
}
